package com.ingrun.tuboshu.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.ingrun.tuboshu.entity.SysAdmin;
import com.ingrun.tuboshu.entity.SysUser;
import com.ingrun.tuboshu.entity.vo.UpdPasswordQ;
import com.ingrun.tuboshu.entity.vo.UserListQ;
import com.ingrun.tuboshu.entity.vo.UpdUserQ;
import com.ingrun.tuboshu.service.ISysUserService;
import com.ingrun.tuboshu.utils.Response;
import com.ingrun.tuboshu.utils.params.PageHelperList;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表	 前端控制器
 * </p>
 *
 * @author ingrun
 * @since 2025-01-23
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "用户表")
public class SysUserController {

    @Autowired
    private ISysUserService sysUserService;

    // 用户注册
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    @SaCheckLogin(type = "admin")
    public Response<Boolean> register(@RequestBody SysUser sysUser) {
        return Response.success(sysUserService.register(sysUser));
    }

    // 管理员重置密码
    @PostMapping("/adminResetPassword")
    @Operation(summary = "管理员重置密码")
    @SaCheckLogin(type = "admin")
    public Response<Boolean> adminResetPassword(@RequestBody UpdPasswordQ query) {
        return Response.success(sysUserService.adminResetPassword(query));
    }

    // 用户列表
    @GetMapping("/userList")
    @Operation(summary = "用户列表")
    @SaCheckLogin(type = "admin")
    public Response<PageHelperList<SysUser>> userList(@ModelAttribute UserListQ query) {
        return Response.success(sysUserService.userList(query));
    }

}
